<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<% 
 /**
  功能名称:注册用户
  创建时间:2010-7-8
  创建人:
**/
%>
<%
String path = request.getContextPath();
%>
<html>
  <head>
    <title>注册用户</title>
	<link href="<%=path %>/css/index_css.css" rel="stylesheet" type="text/css" />
	<script language="javascript" src="<%=path %>/js/syAjax.js"></script>
	<script language="javascript" src="<%=path %>/js/validate.js"></script>
	<script src="<%=path%>/dwr/engine.js"></script>
    <script src="<%=path%>/dwr/util.js"></script>
    <script src="<%=path%>/dwr/interface/shiyueDwr.js"></script>
	<script type="text/javascript">
		var chkAccount =true;
		var chkUserIdResult=false;
		function onlyNum(obj){
			var re = /^[0-9]+.?[0-9]*$/;
            if(obj.value!='' && !re.test(obj.value)){           
               return false;
            }else{
            	return true;
            }
		}
		function doSubmitForm(){
			if(!isNumOrEng(document.getElementById('userId'))){
				if('${user.userType}'==1){
					alert('请输入合法的学籍编号');
				}else{
					alert('请输入合法的人事编号');
				}
				return;
			}
			
			if(chkUserIdResult==false){
				if('${user.userType}'==1){
					alert('该学籍编号已存在');
				}else{
					alert('该人事编号已存在');
				}
				return;
			}
				if(!isNumOrEng(document.getElementById('account'))){
				alert('请输入合法的帐号');
				return;
			}
			if(document.getElementById('name').value.length==0 || document.getElementById('name').value.length>25){
				alert('姓名不能为空，且必须小于25个字符');
				return;
			}
			
			if(document.getElementById('address').value.length>50){
				alert('家庭地址必须小于50个字符');
				return;
			}
			
			//闷男 根据周总2011-7-5测试报告267条 去掉 电话数字验证 身份证验证
			
			if(chkAccount==false){
				alert('该帐号已被占用');
			}
			var account = document.getElementById('account').value;
			var userId = document.getElementById('userId').value;
			var name = document.getElementById('name').value;
			var pwd = document.getElementById('pwd').value;
			var sex = document.getElementById('sex').value;
			var mobileNumber1 = document.getElementById('mobileNumber1').value;
			var idNumber = document.getElementById('idNumber').value;
			var email = document.getElementById('email').value;
			var address = document.getElementById('address').value;
			syAjax.request("post","<%=path %>/saveUserAction.action","user.userId="+userId+"&user.userType=${user.userType}&user.account="+account+"&user.name="+name+"&user.password="+pwd+"&user.sex="+sex+"&user.mobileNumber1="+mobileNumber1+"&user.idNumber="+idNumber+"&user.email="+email+"&user.address="+address+"&classId=${requestScope.classId}&saveOrgId=${requestScope.saveOrgId}",{success:initSuccessResult,fail:onFail,type:'plain'});
		}
		
		
		function checkAccount(){
			var account = document.getElementById('account').value;
			if(account!=null && account!=""){
				syAjax.request("post","<%=path %>/checkAccountUserAction.action","user.account="+account,{success:initSuccessResult3,fail:onFail,type:'plain'});
			}
			
		}
		
		function checkUserId(){
			if(!isNumOrEng(document.getElementById('userId'))){
				if('${user.userType}'==1){
					alert('请输入合法的学籍编号');
				}else{
					alert('请输入合法的人事编号');
				}
				return;
			}
			var userId = document.getElementById('userId').value;
			if(userId!=null && userId!=""){
				syAjax.request("post","<%=path %>/checkUserIdUserAction.action","user.userId="+userId+"&user.userType=${user.userType}",{success:initSuccessResult5,fail:onFail,type:'plain'});
			}
			
		}
		
		function initSuccessResult5(response){
			if(response=="false"){
				chkUserIdResult=false;
				if('${user.userType}'==1){
					alert('该学籍编号已存在');
				}else{
					alert('该人事编号已存在');
				}
				document.getElementById('userId').select();
			}
			if(response=="true"){
				chkUserIdResult=true;
			}
		}
		
		function initSuccessResult3(response){
			if(response=="false"){
				chkAccount=false;
				alert('该帐号已被占用');	
				document.getElementById('account').select();
				
			}else{
				chkAccount=true;
			}
		}
		
		
		function initSuccessResult(response){
			if(response.indexOf("true")!=-1&&response.length>4){
			    alert(response.substring(4)+"已经设置为审核字段，需要在学籍中审核通过后生效");
				window.returnValue='true';
				window.close();
			}else if(response.indexOf("true")!=-1){
			window.returnValue='true';
				window.close();
			}
			if(response=="Userfull"){
				alert('用户已添加成功，但该年级人数已满，无法进行分班！');
				window.returnValue='true';
				window.close();
			}
			
			
		}
		function onFail(){
			alert('网络繁忙，请稍后再试');
		}
		
	function load(){
		shiyueDwr.findCodeHTMLByCodeMaintenanceTypeId("sex","user.sex",getsexCallBack);//性别
	}	
		//性别
    function getsexCallBack(map)
    {
      document.getElementById("sexspan").innerHTML=map;
    }
    
    function ckz(z) {
		var arr = z.match(/^\d+$/);
		if(arr==null) {
			return false;
		}else {
			return true;
		}
	}
	
	//2011-7-18 闷男 按回车键跳到下一元素
		function document.onkeydown(){
		if(event.keyCode==13)
			if(document.activeElement && document.activeElement.type=='button') {
				doSubmitForm();
			}else {
				event.keyCode=9;
			}
		}
	</script>
  </head>
  
  <body bgcolor="#ECE9D8" onload="load();">
  <form action="<%=path%>/saveUserAction.action" method="post">
  <input type="hidden" name="user.userType" value="${user.userType }">
    <table width="650" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="25" align="left" valign="bottom" bgcolor="#ECE9D8" class="f_8">&nbsp;&nbsp;&nbsp;&nbsp;注：<span class="f_11">*</span>为必填项</td>
  </tr>
  <tr>
    <td align="center" valign="top" bgcolor="#ECE9D8"><table width="95%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="1" bgcolor="#ABA899"></td>
      </tr>
      <tr>
        <td height="1" bgcolor="#FFFFFF"></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td height="25" align="left" valign="top" bgcolor="#ECE9D8"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      
       <tr>
        <td width="15%" height="30" align="right"><span class="f_8"><span class="f_11">*</span></span>
        <c:if test="${user.userType ==1}">学籍编号：</c:if>
        <c:if test="${user.userType ==2 || user.userType ==3}">人事编号：</c:if> 
        </td>
        <td width="26%" align="left">
        <input id="userId" type="text" name="user.userId" style="width: 90px;" onchange="checkUserId();" /></td>
        <td width="56%" align="left">
            <img src="<%=path%>/images/icon_21.gif" width="15" height="15" align="absmiddle" /> <c:if test="${user.userType ==1}">学籍编号：</c:if>
        <c:if test="${user.userType ==2 || user.userType ==3}">人事编号：</c:if>请输入英文、数字等字符。
      
        
        
        </td>
        <td width="3%" align="left">&nbsp;</td>
      </tr>
      
  
      
      
      <tr>
        <td width="15%" height="30" align="right"><span class="f_8"><span class="f_11">*</span></span> 帐号：</td>
        <td width="26%" align="left"><input id="account" type="text" name="user.account" onblur="checkAccount();" style="width:150px;" /></td>
        <td width="56%" align="left"><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td align="left" class="tb_11 border_4 f_8"><img src="<%=path%>/images/icon_21.gif" width="15" height="15" align="absmiddle" /> <span id="chkAccount">帐号:请用英文、数字、下划线等字符。</span></td>
          </tr>
        </table></td>
        <td width="3%" align="left">&nbsp;</td>
      </tr>
      <tr>
        <td height="30" align="right"><span class="f_8"><span class="f_11">*</span></span> 姓名：</td>
        <td align="left"><input id="name" type="text" name="user.name" style="width:150px;" /></td>
        <td align="left"><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td align="left" class="tb_11 border_4 f_8"><img src="<%=path%>/images/icon_21.gif" width="15" height="15" align="absmiddle" /> 姓名:请用字母、汉字、数字等字符</td>
          </tr>
        </table></td>
        <td align="left">&nbsp;</td>
      </tr>
      <tr>
        <td height="30" align="right">输入密码：</td>
        <td align="left"><input id="pwd" type="password" name="user.password" style="width:150px;" /></td>
        <td align="left"><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td align="left" class="tb_11 border_4 f_8"><img src="<%=path%>/images/icon_21.gif" width="15" height="15" align="absmiddle" /> 密码:为0―10位,限用英文、数字等符号,不填与帐号一致。</td>
          </tr>
        </table></td>
        <td align="left">&nbsp;</td>
      </tr>
      <tr>
        <td height="30" align="right">性别：</td>
        <td align="left"><span id="sexspan"></span></td>
        <td align="left">&nbsp;</td>
        <td align="left">&nbsp;</td>
      </tr>
      <tr>
        <td height="30" align="right">手机号码：</td>
        <td align="left"><input id="mobileNumber1" type="text" name="user.mobileNumber1" style="width:150px;" /></td>
        <td align="left"><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td align="left" class="tb_11 border_4 f_8"><img src="<%=path%>/images/icon_21.gif" width="15" height="15" align="absmiddle" /> 请填写手机号。</td>
          </tr>
        </table></td>
        <td align="left">&nbsp;</td>
      </tr>
      <tr>
        <td height="30" align="right">身份证号：</td>
        <td align="left"><input id="idNumber" type="text" name="user.idNumber" style="width:150px;" /></td>
        <td align="left"><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td align="left" class="tb_11 border_4 f_8"><img src="<%=path%>/images/icon_21.gif" width="15" height="15" align="absmiddle" /> 请填写身份证号。</td>
          </tr>
        </table></td>
        <td align="left">&nbsp;</td>
      </tr>
      <tr>
        <td height="30" align="right">电子邮件：</td>
        <td align="left"><input id="email" type="text" name="user.email" style="width:150px;" /></td>
        <td align="left"><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td align="left" class="tb_11 border_4 f_8"><img src="<%=path%>/images/icon_21.gif" width="15" height="15" align="absmiddle" /> 填写有效的电子邮箱地址。</td>
          </tr>
        </table></td>
        <td align="left">&nbsp;</td>
      </tr>
      <tr>
        <td height="30" align="right">家庭地址：</td>
        <td align="left"><input id="address" type="text" name="user.address" style="width:150px;" /></td>
        <td align="left">&nbsp;</td>
        <td align="left">&nbsp;</td>
      </tr>
      <tr>
        <td colspan="4" align="center">&nbsp;</td>
        </tr>
      <tr>
        <td colspan="4" align="center"><table width="95%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td height="1" bgcolor="#ABA899"></td>
          </tr>
          <tr>
            <td height="1" bgcolor="#FFFFFF"></td>
          </tr>
        </table></td>
        </tr>
      <tr>
        <td height="30" colspan="3" align="center"><input type="button" onclick="doSubmitForm();" name="Submit" value="提 交" /></td>
        <td align="left">&nbsp;</td>
      </tr>
      
    </table></td>
  </tr>
</table>
</form>
  </body>
</html>
